﻿Imports System.Windows.Input
Imports Microsoft.Practices.Prism.Commands
Imports System.Drawing

''' <summary>
''' Classe  de base pour tous les  onglets
''' </summary>
''' <remarks></remarks>
Public Class ViewModelTabSectionBase
    Implements OMANE.Common.UI.IViewModelTabSection
    Implements ComponentModel.INotifyPropertyChanged
    Implements Windows.Input.ICommand


    Private _title As String
    Private _icone As String
    Private _IsClosable As Boolean

    Public Sub New()
        _IsClosable = True
    End Sub

    ''' <summary>
    ''' Icone de l'onglet
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>Valeur par defaut: "pack://application:,,,/OMANE.Common.UI.Theme;component/Images/compass.png"</remarks>
    Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone
        Get
            If String.IsNullOrEmpty(_icone) Then Return "pack://application:,,,/OMANE.Common.UI.Theme;component/Images/compass.png"
            Return _icone
        End Get
        Set(ByVal value As String)
            _icone = value
        End Set
    End Property

    ''' <summary>
    ''' Titre de l'onglet
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Title As String Implements Common.UI.IViewModelTabSection.Title
        Get
            Return _title
        End Get
        Set(ByVal value As String)
            _title = value
        End Set
    End Property

    ''' <summary>
    ''' L'onglet est-il fermable
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property IsClosable As Boolean Implements Common.UI.IViewModelTabSection.IsClosable
        Get
            Return _IsClosable
        End Get
        Set(value As Boolean)
            _IsClosable = value
            OnPropertyChanged("IsClosable")
        End Set
    End Property

    Private _CloseCommand As ICommand
    Public ReadOnly Property CloseCommand As ICommand
        Get
            If _CloseCommand Is Nothing Then
                _CloseCommand = New delegateCommand(AddressOf CloseExecute)
            End If
            Return _CloseCommand
        End Get
    End Property

    Protected Overridable Sub CloseExecute()
        MsgBox("Fermeture de l'onglet demandée")
    End Sub

    ''' <summary>
    ''' Declenche l'evenement PropertyChanged
    ''' </summary>
    ''' <param name="propname"></param>
    ''' <remarks></remarks>
    Protected Sub OnPropertyChanged(propname As String)
        RaiseEvent PropertyChanged(Me, New ComponentModel.PropertyChangedEventArgs(propname))
    End Sub

    ''' <summary>
    ''' Permet d'executer une commande
    ''' </summary>
    ''' <param name="commandname"></param>
    ''' <remarks></remarks>
    Protected Overridable Sub ExecuteCommand(commandname As String)

    End Sub

    Private Function CanExecute(parameter As Object) As Boolean Implements Windows.Input.ICommand.CanExecute
        Return True
    End Function

    Private Sub Execute(parameter As Object) Implements Windows.Input.ICommand.Execute
        ExecuteCommand(parameter)
    End Sub

    Private Event CanExecuteChanged(sender As Object, e As EventArgs) Implements Windows.Input.ICommand.CanExecuteChanged
    Private Event PropertyChanged(sender As Object, e As ComponentModel.PropertyChangedEventArgs) Implements ComponentModel.INotifyPropertyChanged.PropertyChanged

End Class
